// pages/orgbill/orgbill.js
var app = getApp();
const util = require("../../utils/util.js");
const utils = require("../../utils/timeTool.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    orgId:'',
    pageSize: 10,
    pageNumber: 1,
    list:[],
    totalPages:1,
    name:'',
  },
  getOrgAccountCashApplyList(){
    var that = this
    app.req({
      url: "orgmini/orgAccount/getOrgAccountBillList",
      data: {
        orgId: that.data.orgId,
        status:1,
        pageSize: that.data.pageSize,
        pageNumber: that.data.pageNumber
      },
      method: "post",
      success: function (res) {
        if (res.code == 200) {
          var rows = res.data.rows
          for (var i in rows) {
            rows[i].applyTimes = utils.itemDateToShow(rows[i].applyTime, 1, false, false).split('月')[0]+'月'
            rows[i].applyTime = utils.itemDateToShow(rows[i].applyTime, 1, true, false).split('年')[1]
          }
          if(that.data.pageNumber==1){
            that.setData({
              list: rows,
              totalPages: res.data.totalPages
            })
          }else{
            that.setData({
              list: that.data.list.concat(rows),
              totalPages: res.data.totalPages
            })
          }
          
        }
      }
    });
  },
  todetail(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    var orgid = e.currentTarget.dataset.orgid;
    var type = ''
    if (e.currentTarget.dataset.type==5){
      type=5
    }
    wx.navigateTo({
      url: '/pages/orgbillDetail/orgbillDetail?id=' + id + '&orgid=' + orgid + '&paytype='+type,
    })
  },
  topage: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name;
    wx.navigateTo({
      url: '/pages/myCardNew/myCardNew?type=visitor&id=' + id + '&name=' + name,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      orgId: options.id,
      name:options.name
    })
    wx.setNavigationBarTitle({
      title: this.data.name
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      pageNumber:1
    })
    this.getOrgAccountCashApplyList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onShow()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    if(that.data.totalPages>that.data.pageNumber){
      that.setData({
        pageNumber:that.data.pageNumber*1 + 1
      })
      that.getOrgAccountCashApplyList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})